package com.yanfan.energybilling.tdengine;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Order(99)
@Component
public class TDDeviceEnergyDeductionRecordApplicationStarted implements ApplicationRunner {

    @Autowired(required = false)
    private TDEnergyDeductionRecordMapper tdEnergyDeductionRecordMapper;

    @Value("${spring.datasource.druid.tdengine-server.enabled:false}")
    private Boolean enabled;
    @Value("${spring.datasource.druid.tdengine-server.dbName}")
    private String dbName;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        //先获取TDengine的配置，检测TDengine是否已经配置
        if ( enabled && Objects.nonNull(tdEnergyDeductionRecordMapper)) {
            //创建数据库表
            tdEnergyDeductionRecordMapper.createTable(dbName);
        }
    }
}
